package section10;

import java.io.*;

public class App10_3 {
    public static void main(String[] args) {
        try {
            FileOutputStream fout = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\text.txt");
            DataOutputStream dout=new DataOutputStream(fout);

            dout.writeInt(10);
            dout.writeLong(12345);
            dout.writeFloat(3.14159263456f);
            dout.writeDouble(987654321.123);
            dout.writeBoolean(true);
            dout.writeChars("hello world!");
        }
        catch (FileNotFoundException fnf){}
        catch (IOException ioe){}

        try (FileInputStream fin=new FileInputStream("C:\\Users\\Administrator\\Desktop\\text.txt");
             DataInputStream din=new DataInputStream(fin);)
        {
            System.out.println(din.readInt());
            System.out.println(din.readLong());
            System.out.println(din.readFloat());
            System.out.println(din.readDouble());
            System.out.println(din.readBoolean());

            char ch;
            while ((ch= din.readChar())!='\0')
                System.out.print(ch);
        }
        catch (FileNotFoundException fnf){System.out.println("抱歉，文件未找到！");}
        catch (IOException ioe){}
    }
}
